package cn.edu.suse.epilepsy.controller;

import cn.edu.suse.epilepsy.common.R;
import cn.edu.suse.epilepsy.entity.dto.DoctorAddDto;
import cn.edu.suse.epilepsy.entity.dto.SearchDoctorDto;
import cn.edu.suse.epilepsy.entity.pojo.DoctorManage;
import cn.edu.suse.epilepsy.service.DoctorManageService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: QingShu
 * @Date: 2024/7/7 23:48
 */
@Controller
@ResponseBody
@RequestMapping("/doctormanage")
public class DoctorManageController {
    @Autowired
    private DoctorManageService doctorManageService;
    @PostMapping("/add")
    public R addDoctor(@RequestBody DoctorAddDto dto) {
        DoctorManage doctorManage = doctorManageService.addDoctor(dto);
        return R.success(doctorManage);
    }
    @GetMapping("/all")
    public R selectAllDoctor() {

        return R.success(doctorManageService.selectAllDoctor());
    }
    @GetMapping("/page")
    public R getDoctorPage(@RequestParam(defaultValue = "1") int current,
                           @RequestParam(defaultValue = "12") int size) {
        Page<DoctorManage> page = new Page<>(current, size);
        QueryWrapper<DoctorManage> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id"); // 按照 id 从大到小排序
        IPage<DoctorManage> result = doctorManageService.page(page, queryWrapper);
        return R.success(result);
    }
    @PostMapping("/update")
    public R updateDoctor(@RequestBody DoctorManage doctorManage){
        int i = doctorManageService.updateDoctor(doctorManage);
        return R.success(i);
    }
    @PostMapping("/search")
    public R searchDoctors(@RequestBody SearchDoctorDto dto) {
        return R.success(doctorManageService.searchDoctors(dto.getName(), dto.getHospital(),
                dto.getStatus(), dto.getDepartment()));
    }

}
